package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class OSSConfiguration {
    @Autowired
    private AliOssProperties aliOssProperties;

    //为AliOssUtil工具类中字段初始化值，就是把yml文件中映射到配置属性类字段中的值拿过来，
    //然后封装成工具类对象，以便后面调用工具类中upload方法
    @Bean
    public AliOssUtil aliOssUtil(){
        log.info("开始创建阿里云oss工具类");
        return new AliOssUtil(aliOssProperties.getEndpoint(), aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(), aliOssProperties.getBucketName());
    }

}
